<template>
  <!-- 面包屑 -->
  <Breadcrumb />
  <el-table :data="orderList" style="width: 100%">
    <el-table-column prop="id" label="id" width="180" />
    <el-table-column prop="order_sn" label="订单编号" width="220" />
    <el-table-column prop="order_time" label="购买时间" width="180" />
    <el-table-column prop="manber_id" label="购买人" width="180" />
    <el-table-column prop="price" label="订单总价格" width="180" />
    <el-table-column label="订单状态">
      <template #default="scope">
        <el-switch
          :active-value="1"
          :inactive-value="2"
          v-model="scope.row.status"
          class="ml-2"
          @change="setStatus(scope.row.id, $event)"
        />
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button
          size="small"
          link
          type="primary"
          @click="handleEdit(scope.$index, scope.row)"
        >
          修改状态
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <!-- 对话弹框 -->
  <el-dialog
    v-model="flag"
    :title="flags ? '修改状态' : '编辑广告位'"
    :show-close="false"
    width="800"
  >
    <el-form
      style="max-width: 600px"
      :model="forms"
      label-width="auto"
      class="demo-ruleForm"
      :size="formSize"
      status-icon
    >
      <el-form-item label="位置类型" prop="region">
        <el-select v-model="forms.status" placeholder="">
          <el-option label="待付款" value="待付款" />
          <el-option label="待发货" value="待发货" />
          <el-option label="待收货" value="待收货" />
          <el-option label="已完成" value="已完成" />
          <el-option label="已退货" value="已退货" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="updateForm(ruleFormRef)">
          确定
        </el-button>
        <el-button @click="resetForm(ruleFormRef)">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script setup >
import { ref, reactive, toRefs, onMounted } from "vue";
import Breadcrumb from "../../components/bread/Breadcrumb.vue";
import { getOrderListAPI } from "../../api/order";

onMounted(async () => {
  getOrderListDate();
});

// 刷新列表
const render = () => {
  getOrderListDate();
};

const getOrderListDate = async () => {
  //获取列表数据
  let res = await getOrderListAPI();
  orderList.value = Object.values(res.data.data);
  console.log(orderList.value);
};

const orderList = ref([]);

const flag = ref(false); //控制弹窗显隐
const flags = ref(true); //控制添加、修改
const forms = ref({
  status: "",
});
// 点击编辑按钮
const handleEdit = (index, row) => {
  flag.value = true; //控制弹窗显示
  // 回显数据
  forms.value = row;
};
// 编辑弹窗确定
const updateForm = async (formEl) => {
  flag.value = false; //控制弹窗隐藏
  console.log(forms.value);
};
// 添加/编辑弹窗取消
const resetForm = (formEl) => {
  flag.value = false; //控制弹窗隐藏
};
// switch
const setStatus = (id, event) => {};
</script>
<style scoped lang="less">
</style>